package com.wl.boot.batch.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * @author wanglu0
 * @date 2021-08-18 16:18
 */
@Configuration
@EnableAsync
public class AsyncThreadConfig {
    private static Logger logger = LoggerFactory.getLogger(AsyncThreadConfig.class);

    @Bean
    public Executor asyncServiceExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(8);
        executor.setMaxPoolSize(1000);
        executor.setQueueCapacity(5000);
        //线程名称前缀
        executor.setThreadNamePrefix("AsyncExecutor - ");
        executor.setKeepAliveSeconds(30000);
        executor.initialize();
        return executor;
    }
}
